package com.rd.student.dashuju.sunwenzhuo.Test1.LinkListDemo;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;


public class LinkedListTest2 {
    public static void main(String[] args) {
        LinkedList list = new LinkedList();


        Student s1 = new Student("孙文卓", "大数据", "1班", 19);
        Student s2 = new Student("王博", "大数据", "3班", 21);
        Student s3 = new Student("郑成祥", "大数据", "1班", 21);
        Student s4 = new Student("郑睿娴", "大数据", "1班", 19);
        Student s5 = new Student("王高博", "物联网", "3班", 20);


        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);

        Collections.sort(list);

//        System.out.println(list);
/*        for (Object o : list){
            System.out.println(o);
        }*/
        Iterator i = list.iterator();
        while (i.hasNext()) {
            System.out.println(i.next());
        }
        System.out.println("-------------------------");

        Collections.reverse(list);
        Iterator i1 = list.iterator();
        while (i1.hasNext()) {
            System.out.println(i1.next());
        }
    }

}

class Student implements Comparable {
    public String name;
    public String major;
    public String classNum;
    public int age;

    public Student() {

    }

    public Student(String name, String major, String classNum, int age) {

        this.name = name;
        this.major = major;
        this.classNum = classNum;
        this.age = age;

    }

    @Override
    public int compareTo(Object o) {
        Student s = (Student) o;
        if (this.age>s.age){
            return -1;
        }else if (this.age<s.age){
            return 1;
        }
        return 0;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", major='" + major + '\'' +
                ", classNum='" + classNum + '\'' +
                ", age=" + age +
                '}';
    }
}
